package com.cyz.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyz.admin.service.CardService;
import com.cyz.admin.service.PathCardService;
import com.cyz.admin.service.PathService;
import com.cyz.common.bean.Path;
import com.cyz.common.dto.PathDto;
import com.cyz.common.enums.MyEnums;
import com.cyz.common.mapper.PathMapper;
import com.cyz.common.utils.BeanCopyUtil;
import com.cyz.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author 34928
* @description 针对表【path】的数据库操作Service实现
* @createDate 2023-02-22 15:09:34
*/
@Service
public class PathServiceImpl extends ServiceImpl<PathMapper, Path>
    implements PathService {

    @Autowired
    private PathCardService pathCardService;

    @Autowired
    private CardService cardService;
    @Autowired
    private PathService pathService;

    @Override
    public R queryAllPath() {
        return null;
    }

    @Override
    public R updatePath(PathDto pathDto) {
        Path path = BeanCopyUtil.copyBean(pathDto, Path.class);
        boolean flag = updateById(path);
        if(flag){
            return queryPath();
        }
        return R.error(MyEnums.UPDATE_FAIL);
    }

    @Override
    public R addPath(PathDto pathDto) {
        Path path = BeanCopyUtil.copyBean(pathDto, Path.class);
        boolean flag = save(path);
        if(flag){
            return queryPath();
        }
        return R.error(MyEnums.ADD_FAIL);
    }

    @Override
    public R deletePaths(Integer[] ids) {
        boolean flag = removeByIds(Arrays.asList(ids));
        if(flag){
            return queryPath();
        }
        return R.error(MyEnums.DELETE_FAIL);
    }

    @Override
    public R queryPath() {
        List<Path> list = list();
        return R.success(list);
    }
}




